﻿<Window x:Class="CBR_Viewer.PopupWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
        SnapsToDevicePixels="True"
        Height="350" 
        Width="600"         
        Title="Recent"
	    WindowStartupLocation="Manual" 
	    ShowInTaskbar="False" 
	    ResizeMode="NoResize"       
        mc:Ignorable="d"
        DataContext="{Binding Popup, Source={StaticResource Locator}}" 
        SizeToContent="WidthAndHeight" 
        WindowStyle="None"
        BorderThickness="0"
        Background="{DynamicResource ShadeBrush}" 
        >
    <Window.Resources>
        <SolidColorBrush x:Key="SelectedForegroundBrush" Color="Red" />
        <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="BlueViolet" />
        <SolidColorBrush x:Key="HoverBackgroundBrush" Color="Yellow" />

        <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Grid Focusable="True" Name="Grid">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50"/>
                                <ColumnDefinition Width="30"/>
                                <ColumnDefinition Width="330"/>
                                <ColumnDefinition Width="10"/>
                                <ColumnDefinition Width="35"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40"/>
                                <RowDefinition Height="22"/>
                            </Grid.RowDefinitions>
                            
                            <Image 
                                Grid.Column="0"
                                Grid.Row="0"
                                Grid.RowSpan="2"
                                Source="{Binding Path=Thumb}" 
                                Width="42" 
                                Height="56"
                                Margin="0" 
                                Stretch="None"/>
                            <TextBlock 
                                Grid.Column="2"
                                Grid.Row="0"
                                VerticalAlignment="Center"  
                                HorizontalAlignment="Left"
                                ToolTip="{Binding Path=Name}"
                                Text="{Binding Path=Name}" 
                                FontWeight="Bold" 
                                FontSize="18" 
                                TextTrimming="CharacterEllipsis"/>
                            <TextBlock 
                                Grid.Column="2"
                                Grid.Row="1"
                                VerticalAlignment="Center"
                                ToolTip="{Binding Path=FullFileName}"
                                Text="{Binding Path=FullFileName}" 
                                TextTrimming="CharacterEllipsis"/>
                            <TextBlock 
                                Grid.Column="4"
                                Grid.Row="1"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Text="{Binding Path=PageNumberBrc}"/>
                            <TextBlock 
                                Grid.Column="1"
                                Grid.Row="0"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Text="{Binding Path=Index}"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Grid"  Property="Background" Value="#FFF7941E" />
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="False">
                                <Setter TargetName="Grid" Property="Background" Value="#FFF4DCC1"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter TargetName="Grid"  Property="Background" Value="#FFF7941E" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
         </Style>
    </Window.Resources>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="LostKeyboardFocus">
            <cmd:EventToCommand Command="{Binding LostKeyboardFocusCommand}"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="Activated">
            <cmd:EventToCommand Command="{Binding ActivatedCommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <DockPanel>
        <ListBox 
            Margin="2,2,2,2" 
            DockPanel.Dock="Top"
            Name="listBox1"
            ItemsSource="{Binding Path= MyRecentItems}"
            Background="{DynamicResource ShadeBrush}" 
            HorizontalAlignment="Left"
            SelectedIndex="{Binding SelIndex, Mode=TwoWay}"
            AlternationCount="{Binding Path=MyRecentItems.Count}"
            IsTabStop="True" 
                >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="PreviewGotKeyboardFocus">
                    <cmd:EventToCommand Command="{Binding GotKeyboardFocusCommand}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </ListBox>

    </DockPanel>
</Window>
